//
//  CarBuyThingCell.m
//  LoveTrail
//
//  Created by giantumbrella on 15/6/15.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//

#import "CarBuyThingCell.h"
#import "CommonMacro.h"

@interface CarBuyThingCell()
@property (nonatomic,strong) UILabel *colorLabel ;
@property (nonatomic,strong) UIButton *reductionButton;
@property (nonatomic,strong) UIButton *addButton;
@property (nonatomic,strong) UIButton *deleteButton;
@end

@implementation CarBuyThingCell

- (void)awakeFromNib {

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];


}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self initWithSubviews];
    }
    return self;
}

- (void)initWithSubviews
{
    
    //1.添加cell里面的背景
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(10, 15, SCREEN_WIDTH-20, 150)];
    bgView.backgroundColor = [UIColor blueColor];
    [self addSubview:bgView];
    bgView.layer.cornerRadius = 3;
    bgView.clipsToBounds = YES;
    bgView.backgroundColor = UIColorWithRGBA(255, 255, 255, 1);
    bgView.layer.borderColor = UIColorWithRGBA(225, 225, 225, 1).CGColor;
    bgView.layer.borderWidth = 1;
    
    //添加产品图片
    self.productImageView = [[UIImageView alloc] initWithFrame:CGRectMake(bgView.frame.origin.x, bgView.frame.origin.y-3, bgView.frame.size.width*0.36, bgView.frame.size.height*0.8)];
    self.productImageView.backgroundColor = [UIColor greenColor];
    self.productImageView.image = [UIImage imageNamed:@"热卖@2x"];
    [bgView addSubview:self.productImageView];
     self.productImageView.layer.cornerRadius = 3;
     self.productImageView.clipsToBounds = YES;
     self.productImageView.backgroundColor = UIColorWithRGBA(255, 255, 255, 1);
     self.productImageView.layer.borderColor = UIColorWithRGBA(225, 225, 225, 1).CGColor;
     self.productImageView.layer.borderWidth = 1;
    
    //2.添加文字叙述部分
    self.detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(bgView.frame.size.width*0.42, bgView.frame.origin.y, bgView.frame.size.width*0.6, bgView.frame.size.height*0.45)];
    self.detailLabel.textColor = UIColorWithRGBA(171, 171, 171, 1);
    self.detailLabel.font = [UIFont fontWithName:nil size:17];
    [bgView addSubview:self.detailLabel];
    
    
    //3.添加加减件数
    //减
//    CGFloat buttonX = ;
    CGFloat buttonY = bgView.frame.size.height*0.5;
    CGFloat buttonW = bgView.frame.size.width*0.06;
    CGFloat buttonH = bgView.frame.size.height*0.1;
    self.reductionButton = [[UIButton alloc] initWithFrame:CGRectMake(bgView.frame.size.width*0.42, buttonY,buttonW , buttonH)];
    self.reductionButton.tag = 1000;
    [self.reductionButton setTitle:@"-" forState:UIControlStateNormal];
    [self.reductionButton setTitleColor:UIColorWithRGBA(194, 194, 194, 1) forState:UIControlStateNormal];
    self.reductionButton.layer.borderWidth = 1;
    self.reductionButton.layer.borderColor = UIColorWithRGBA(228, 228, 228, 1).CGColor;
    [bgView addSubview:self.reductionButton];
    [self.reductionButton addTarget:self action:@selector(actionButton:) forControlEvents:UIControlEventTouchUpInside];
    
    //加减后的数字
    self.numLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.reductionButton.frame.size.width+self.reductionButton.frame.origin.x+3, buttonY-3, bgView.frame.size.width*0.1,bgView.frame.size.height*0.14)];
   
    self.numLabel.textColor = UIColorWithRGBA(194, 194, 194, 1);
    self.numLabel.layer.borderColor = UIColorWithRGBA(228, 228, 228, 1).CGColor;
    self.numLabel.layer.borderWidth = 1;
    [bgView addSubview:self.numLabel];
//    self.numLabel.tag = 1000;

    //加
    self.addButton = [[UIButton alloc] initWithFrame:CGRectMake(self.numLabel.frame.size.width+self.numLabel.frame.origin.x+3, buttonY, buttonW, buttonH)];
    self.addButton.tag = 1001;
    self.addButton.layer.borderWidth = 1;
    self.addButton.layer.borderColor = UIColorWithRGBA(228, 228, 228, 1).CGColor;
    [self.addButton setTitle:@"+" forState:UIControlStateNormal];
    [self.addButton setTitleColor:UIColorWithRGBA(194, 194, 194, 1) forState:UIControlStateNormal];
    [bgView addSubview:self.addButton];
    [self.addButton addTarget:self action:@selector(actionButton:) forControlEvents:UIControlEventTouchUpInside];
    
    //4 价钱
    self.priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(bgView.frame.size.width*0.67+3,buttonY-8, bgView.frame.size.width*0.3, bgView.frame.size.height*0.2)];
    self.priceLabel.textColor = UIColorWithRGBA(231, 3, 62, 1);
    [self.priceLabel setFont:[UIFont systemFontOfSize:22]];
    self.priceLabel.textAlignment = NSTextAlignmentCenter;
        [bgView addSubview:self.priceLabel];
    
    //5.商品颜色
    self.colorLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.reductionButton.frame.origin.x, self.numLabel.frame.origin.y+self.numLabel.frame.size.height+18, bgView.frame.size.width*0.16, bgView.frame.size.height*0.14)];
    self.colorLabel.textAlignment = NSTextAlignmentCenter;
    self.colorLabel.textColor = UIColorWithRGBA(132, 127, 127, 1);
    self.colorLabel.font = [UIFont fontWithName:nil size:13];
    self.colorLabel.layer.borderColor = UIColorWithRGBA(228, 228, 228, 1).CGColor;
    self.colorLabel.layer.borderWidth = 1;

    [bgView addSubview:self.colorLabel];
}

- (void)actionButton:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(reductionAddButton:)]) {
        [self.delegate reductionAddButton:button];
    }
}
@end
